package mo.offer_version2;

import java.util.Stack;

public class L09 {

    private int size = 0;
    private Stack<Integer> tail = new Stack<>();
    private Stack<Integer> head = new Stack<>();

    public L09() {

    }

    public void appendTail(int value) {
        tail.push(value);
        size++;
    }

    public int deleteHead() {
        if (size == 0) {
            return -1;
        }
        if (head.isEmpty()) {
            int idx = 0;
            while (idx < size) {
                head.push(tail.pop());
                idx++;
            }
        }
        size--;
        return head.pop();
    }

    public static void main(String[] args) {
        L09 test = new L09();
        System.out.println(test.deleteHead());
        test.appendTail(5);
        test.appendTail(2);
        System.out.println(test.deleteHead());
        System.out.println(test.deleteHead());
    }
}
